#pragma once
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

class Inet_Addr
{
private:
    sockaddr_in _addr;
    std::string _ip;
    uint16_t _port;
private:
    void toHost()
    {
        _ip = inet_ntoa(_addr.sin_addr);
        _port = ntohs(_addr.sin_port);
    }

public:
    Inet_Addr(const struct sockaddr_in& addr)
        :_addr(addr)
    {
        toHost();
    }
    uint16_t Port()
    {
        return _port;
    }
    std::string Ip()
    {
        return _ip;
    }
    sockaddr_in Addr()
    {
        return _addr;
    }
    bool operator==(const Inet_Addr& addr)
    {
        return addr._ip == _ip && addr._port == _port;
    }
    ~Inet_Addr()
    {}
};